package org.JWCB.friend.controller.user;

import org.JWCB.common.core.constants.HttpConstants;
import org.JWCB.common.core.controller.BaseController;
import org.JWCB.friend.domain.user.dto.*;
import org.JWCB.common.core.domain.vo.LoginUserVo;
import org.JWCB.common.core.domain.vo.R;
import org.JWCB.friend.domain.user.vo.UserDetailVo;
import org.JWCB.friend.service.user.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RequestMapping("user")
@RestController
public class UserController extends BaseController {
    @Autowired
    private UserService userService;
    @PostMapping("/sendCode")
    public R<Void> sendCode(@RequestBody @Validated UserSendCodeDto userSendCodeDto) {

        return toR( userService.sendCode(userSendCodeDto));
    }

    @PostMapping("/updateUserPhone")
    public R<Void> updateUserPhone(@RequestBody UserUpdatePhoneDto userUpdatePhoneDto) {
        return toR(userService.updateUserPhone(userUpdatePhoneDto));
    }

    @PostMapping("/login")
    public R<String> login(@RequestBody @Validated UserLoginDto userLoginDto){
        return R.ok(userService.codeLogin(userLoginDto));
    }


    @PostMapping("/logout")
    public R<Void> logout(@RequestHeader(HttpConstants.AUTHENTICATION) String token) {
        return toR(userService.logout(token));
    }

    @GetMapping("/info")
    public R<LoginUserVo> info(@RequestHeader(HttpConstants.AUTHENTICATION) String token) {
        return userService.info(token);
    }



    @GetMapping("/detail")
    public R<UserDetailVo> detail() {
        return userService.detail();
    }


    @PutMapping("/edit")
    public R<Void> edit(@RequestBody @Validated UserEditDto userEditDto) {
        return toR(userService.edit(userEditDto));
    }



    @PutMapping("/headImage/update")
    public R<Void> updateHeadImage(@RequestBody HeadImageUploadDto headImageUploadDto) {
        return toR(userService.updateHeadImage(headImageUploadDto));
    }
}
